<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>
    
    类型定义符typedef - DSRBLOG
    
  </title>
  

  
  
  <link href="atom.xml" rel="alternate" title="DSRBLOG" type="application/atom+xml">
  <link rel="stylesheet" href="asset/css/style.min.css">
  <link rel="stylesheet" href="asset/css/doc.css">
  <script src="asset/app.js"></script>


</head>

<body> <section class="ct-body">
	<div class="container">
		<div class="columns is-variable bd-klmn-columns is-4 is-centered">
			<div class="column is-four-fifths">
				<div class="post-body single-content">
					
					<h1 class="title">
						类型定义符typedef
					</h1>


					<div class="media">
						
						
						<div class="media-content">
							<div class="content">
								<p>
									<span class="date">2022/01/28 01:52 上午</span>
									

									

									<br />
									<span class="tran-tags">Tags:</span>&nbsp;
									
									<a class="tag is-link is-light">#C语言</a>
									

								</p>
							</div>
						</div>

					</div>
				</div>
				<article class="markdown-body single-content">
					<p>类型定义符typedef用来为数据类型取&quot;别名&quot;</p>
<h2><a id="%E4%B8%80%E8%88%AC%E5%BD%A2%E5%BC%8F" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>一般形式</h2>
<pre class="line-numbers"><code class="language-c">typedef 原类型名 新类型名
</code></pre>
<h3><a id="%E4%BE%8B%E5%A6%82" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>例如</h3>
<pre class="line-numbers"><code class="language-c">typedef int INTERGER;
INTERGER a, b; //等价于int a, b
</code></pre>
<h4><a id="typedef%E4%B9%9F%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E5%AE%9A%E4%B9%89%E5%85%B6%E5%AE%83%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%88%AB%E5%90%8D" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>typedef也可以用来定义其它数据类型的别名</h4>
<h5><a id="char%E5%AD%97%E7%AC%A6%E4%B8%B2" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>char字符串</h5>
<pre class="line-numbers"><code class="language-c">typedef char NAME[20];
NAME s1, s2; //等价于char s1[2], s2[20]
</code></pre>
<h5><a id="struct%E7%BB%93%E6%9E%84%E4%BD%93" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>struct结构体</h5>
<pre class="line-numbers"><code class="language-c">typedef struct student
{
    成员表列
} STU;

STU b1, b2; //等价于struct student b1, b2;
</code></pre>

				</article>
				<div class="comments-wrap">
					<div class="share-comments">
						

						

						
					</div>
				</div><!-- end comments wrap -->
			</div>
		</div><!-- end columns -->
	</div><!-- end container -->
</section>  














<script src="asset/prism.js"></script>









</body>

</html>